package com.gxa.community.agent.controller;

import com.gxa.community.agent.service.OrderService;
import com.gxa.community.core.pojo.vo.order.WayBillVo;
import com.gxa.community.core.utils.LittleUtils;
import com.gxa.community.core.utils.R;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/agent")
public class OrderController {
    // TODO 调用后台(AgentController), 缓存数据

    final
    OrderService orderService;

    public OrderController(OrderService orderService) {
        this.orderService = orderService;
    }

    /**
     * 查询运单
     * @param page
     * @param size
     * @param wayBillVo
     * @return
     */
    @PostMapping("/queryWaybill")
    public R queryWaybill(Integer page, Integer size, @RequestBody WayBillVo wayBillVo) {
        // 数据校验
        if (page == null || page < 1) page = 1;
        if (size == null || size < 1 || size > 100) size = 5;

        if (LittleUtils.checkNum(wayBillVo.getStatus(), 1, 4)) return R.error("运单状态有误");

        int i = LittleUtils.checkStartEndTime(wayBillVo.getStartTime(), wayBillVo.getEndTime());
        if (i == 1)
            return R.error("起始时间不能大于结束时间");
        else if (i == 2)
            return R.error("时间范围不允许超过两个月");

        return orderService.queryWaybill(page, size, wayBillVo);
    }


}
